package com.i2bt.app.set.model;

import com.i2bt.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

public class SetListViewAdapter extends BaseAdapter {
	public static int PROGRESS;
	private Context context;
	private List<? extends Map<String, ?>> mData;
	private int mResource;
	private String[] mFrom;
	private int[] mTo;
	private LayoutInflater mLayoutInflater;

	public SetListViewAdapter(Context context,
			List<? extends Map<String, ?>> data, int resource, String[] from,
			int[] to) {
		this.context = context;
		this.mData = data;
		this.mResource = resource;
		this.mFrom = from;
		this.mTo = to;
		this.mLayoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.mData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup parent) {
		// TODO Auto-generated method stub
		contentView = this.mLayoutInflater.inflate(this.mResource, parent,
				false);
		TextView textView = (TextView) contentView.findViewById(mTo[0]);
		textView.setText(this.mData.get(position).get(this.mFrom[0]).toString());
		textView.setTextSize(15);
		ImageView img = (ImageView) contentView.findViewById(mTo[1]);
		if (this.mData.get(position).get(this.mFrom[1]) != null) {
			img.setImageDrawable(context.getResources().getDrawable(
					R.drawable.set_direction));
		}
		return contentView;
	}

}
